<?php

//*******************************************************
//* JAccelerator Component
//* http://fun.kubera.org
//* (C) Radoslaw Kubera
//* license http://www.gnu.org/copyleft/gpl.html GNU/GPL
//*******************************************************

/** ensure this file is being included by a parent file */

defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
global $mosConfig_absolute_path;
include_once ($mosConfig_absolute_path."/components/com_joomlacache/joomlacache.php");

function com_install() {
	global $mosConfig_absolute_path, $mosConfig_lang;

	if(file_exists($mosConfig_absolute_path."/administrator/components/com_joomlacache/language/$mosConfig_lang.php")) {
		include_once ($mosConfig_absolute_path."/administrator/components/com_joomlacache/language/$mosConfig_lang.php");
	} else {
		include_once ($mosConfig_absolute_path."/administrator/components/com_joomlacache/language/english.php");
	}

	$path = $mosConfig_absolute_path.'/components/com_joomlacache/';

	global $database;

	$database->setQuery("update #__components set link='' where link='option=com_joomlacache'");
	$database->query();

	@mkdir($path.'cache');

	JoomlaCacheInstallPlugin();
	JoomlaCacheAbout();
}

function JoomlaCacheInstallPlugin() {
	global $database, $mosConfig_dbprefix, $mosConfig_absolute_path;
	$list = $database->getTableList();
	$table = $mosConfig_dbprefix.'plugins';
	$path = $mosConfig_absolute_path.'/plugins/system/';

	if(!in_array($table, $list)) {
		$table = $mosConfig_dbprefix.'mambots';
		$path = $mosConfig_absolute_path.'/mambots/system/';
	}

	$database->setQuery("select * from $table where element = 'joomlacache'");
	$database->loadObject($element);
	if(!$element) {
		$path_install = $mosConfig_absolute_path.'/components/com_joomlacache/plugin/';
		if(copy($path_install.'joomlacache.php', $path.'joomlacache.php')) {
			if(copy($path_install.'joomlacache.xm_', $path.'joomlacache.xml')) {
				$database->setQuery("insert into $table set name='JAccelerator Plugin', element='joomlacache', folder='system', published='1'");
				$database->query();
				return 1;
			}
		}
	}
	return 0;
}

?>
